package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsLineBodyAbnormalHistoryMapper;
import me.zhengjie.pojo.entity.PageBean;
import me.zhengjie.pojo.entity.WcsLineBodyAbnormalHistory;
import me.zhengjie.pojo.vo.ReturnVo;
import me.zhengjie.sqlservice.WcsLineBodyAbnormalHistoryService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsLineBodyAbnormalHistoryServiceImpl extends ServiceImpl<WcsLineBodyAbnormalHistoryMapper, WcsLineBodyAbnormalHistory> implements WcsLineBodyAbnormalHistoryService {
    private final WcsLineBodyAbnormalHistoryMapper wcsLineBodyAbnormalHistoryMapper;

    @Override
    public boolean insert(WcsLineBodyAbnormalHistory wcsLineBodyAbnormalHistory) {
        return wcsLineBodyAbnormalHistoryMapper.insert(wcsLineBodyAbnormalHistory) >0;
    }

    @Override
    public PageBean Page(Integer page, Integer pageSize, String containerCode, String abnormalInformation, Integer palletId, List<LocalDateTime> times) {
        if(page==null)page=1;
        if(pageSize==null)pageSize=10;
        LocalDateTime start=null,end=null;
        if(times!=null&&times.size()==2)
        {
            start  =times.get(0);
             end  =times.get(1);
        }
        else if(times!=null&&times.size()==1)
        {
            start  =times.get(0);
        }
       PageHelper.startPage(page,pageSize);
        List<WcsLineBodyAbnormalHistory> wcsLineBodyAbnormalHistories = wcsLineBodyAbnormalHistoryMapper.Page(page, pageSize, containerCode, abnormalInformation, palletId, start, end);

        Page<WcsLineBodyAbnormalHistory> p=(Page<WcsLineBodyAbnormalHistory>) wcsLineBodyAbnormalHistories;
        PageBean pageBean = new PageBean(p.getTotal(),wcsLineBodyAbnormalHistories);

        return pageBean;
    }



//    @Override
//    public List<WcsLineBodyAbnormalHistory> selectByContainerCode(String containerCode) {
//
//        LambdaQueryWrapper<WcsLineBodyAbnormalHistory> wcsLineBodyAbnormalHistoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalHistoryLambdaQueryWrapper.eq(WcsLineBodyAbnormalHistory::getContainerCode,containerCode);
//        return wcsLineBodyAbnormalHistoryMapper.selectList(wcsLineBodyAbnormalHistoryLambdaQueryWrapper);
//
//    }
//
//    @Override
//    public List<WcsLineBodyAbnormalHistory> selectByAbnotmalInformation(String information) {
//        LambdaQueryWrapper<WcsLineBodyAbnormalHistory> wcsLineBodyAbnormalHistoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalHistoryLambdaQueryWrapper.eq(WcsLineBodyAbnormalHistory::getAbnormalInformation,information);
//        return wcsLineBodyAbnormalHistoryMapper.selectList(wcsLineBodyAbnormalHistoryLambdaQueryWrapper);
//    }
//
//    @Override
//    public List<WcsLineBodyAbnormalHistory> selectByCreateTime(List<LocalDateTime>times) {
//        LocalDateTime start  =times.get(0);
//        LocalDateTime end  =times.get(1);
//        LambdaQueryWrapper<WcsLineBodyAbnormalHistory> wcsLineBodyAbnormalHistoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        wcsLineBodyAbnormalHistoryLambdaQueryWrapper.between(WcsLineBodyAbnormalHistory::getCreateTime,start,end);
//        return wcsLineBodyAbnormalHistoryMapper.selectList(wcsLineBodyAbnormalHistoryLambdaQueryWrapper);
//    }


}
